package cn.alm.springaihello.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("model")
public class ModelController {

    @Resource
    private OpenAiChatModel chatModel;

    @RequestMapping("chat")
    public String chat(@RequestParam String question) {
        String call = chatModel.call(question);
        return call;
    }

    @RequestMapping(value = "stream", produces = "text/html;charset=UTF-8")
    public Flux<String> stream(@RequestParam String question) {
        Flux<String> stream = chatModel.stream(question);
        return stream;
    }

}
